package com.xzcedu.jdbc;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Properties;

/**
 * @author 徐州城
 * @version 1.0
 */
public class exercise01 {
    @SuppressWarnings("all")
    public static void main(String[] args) throws Exception {

        /**
         * 参考代码，使用方式5 完成
         * 1. 创建news 表
         * 2. 使用jdbc 添加5条数据
         * 3. 修改 id = 1的记录，将content 改成一个新的消息
         * 4. 删除 id = 3的记录
         */
        Properties properties = new Properties();
        properties.load(new FileInputStream("src\\com\\xzcedu\\jdbc\\mysql.properties"));
        //获取相关的值
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
        String driver = properties.getProperty("driver");
        String url = properties.getProperty("url");

        //得到connection 连接
        Connection connection = DriverManager.getConnection(url, user, password);

        String sql = "insert into news values(100,'北京新闻'),(200,'上海新闻'),(300,'广州新闻')";
        Statement statement = connection.createStatement();
        //返回数据的结果
        int rows = statement.executeUpdate(sql);

        System.out.println(rows > 0 ? "成功" : "失败");

        //关闭连接
        statement.close();
        connection.close();
    }
}
